require('./Menu.styl');
const ui = require('clientConfig/util/jsapi/ui');
import { Control } from 'react-keeper';

class Menu extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            show: this.props.show
        };
        
    }
    clickEve(e) {
        let path = e.target.title;
        let title = e.target.attributes["data-value"].value;
        for(let item of this.props.listdata){
            if(this.props.classId == item.classId){
                var classStr = item.title
            }
        }
        Control.go(path,{title,classId:this.props.classId,classStr});
        this.props.onclick && this.props.onclick(e.target.title);
    }
    liItem() {
        return this.props.item.map((item, index) => {
            const Ans = require("images/svg/menu/"+item.icon);
            return (<li key={item.content} title={item.path} data-value={item.content} onClick={this.clickEve.bind(this)}>
                <Ans height='20' width='20' className="svgIcon" />
                <span>{item.content}</span>
            </li>)
        });
    }

    render() {
        const displayShow = {
            display: this.state.show ? 'block' : 'none'
        }
        return (
            <div className="menu" style={displayShow} onClick={()=>{this.setState({show: false})}}>
                <ul className="menu-list" onClick={ (e)=> {e.stopPropagation()}} >
                    {this.liItem()}
                    <span className="icon"></span>
                </ul>
            </div>
        );
    }

    componentWillMount() {
    }

    componentDidMount() {
    }

    componentWillReceiveProps(nextProps) {
        this.setState({
            show: nextProps.show,
        })
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {
        this.setState({
            show: false
        })
    }
}

module.exports = Menu;
